package dev.ece.core.cells.world;

import java.nio.FloatBuffer;

import dev.ece.core.texture.Texture;
import dev.ece.util.lib.Matrix4f;
import dev.ece.util.tools.BufferBuilder;
/**
 * 阴影信息
 * @author 飘渺青衣
 * <b>E-mail：</b>3375758@qq.com
 */
public class ShadowInfo {
	
	private Texture shadowMapping;
	
	private Matrix4f shadowMatrix;
	
	private FloatBuffer shadowMatrixBuffer = BufferBuilder.buildFloatBuffer(64);
	
	private boolean enable;
	
	private int lightIndex;

	public void store() {
		shadowMatrix.store(shadowMatrixBuffer);
		shadowMatrixBuffer.rewind();
	}
	
	public void glUniformShadowInfo(ShadowInfoLocationHandler handler, int index) {
		handler.glUniformShadowInfo(this, index);
	}
	
	/**
	 * 深度图
	 * @return
	 */
	public Texture getShadowMapping() {
		return shadowMapping;
	}

	protected void setShadowMapping(Texture shadowMapping) {
		this.shadowMapping = shadowMapping;
	}

	/**
	 * 阴影矩阵
	 * @return
	 */
	public Matrix4f getShadowMatrix() {
		return shadowMatrix;
	}

	protected void setShadowMatrix(Matrix4f shadowMatrix) {
		this.shadowMatrix = shadowMatrix;
	}

	public boolean isEnable() {
		return enable;
	}

	protected void setLightIndex(int lightIndex) {
		this.lightIndex = lightIndex;
	}

	protected void setEnable(boolean enable) {
		this.enable = enable;
	}

	public FloatBuffer getShadowMatrixBuffer() {
		return shadowMatrixBuffer;
	}
	
	public int getLightIndex() {
		return lightIndex;
	}
	
	public static String getShadowInfoStructString() {
		return "struct ece_ShadowMapping {\n" +
				"bool enable;\n" +  
				"sampler2DShadow shadowMapping;\n" +  
				"mat4 shadowMatrix;\n" +  
				"int lightIndex;\n" +  
			"};\n";
	}
	
}
